//
//  BRPayManager.h
//  BrezzeSaaS
//
//  Created by IOS on 2021/9/14.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <PassKit/PassKit.h>
#import "BRAddCardModel.h"
#import "BRPaymentModel.h"

@import StripePayments;
@import StripeApplePay;

NS_ASSUME_NONNULL_BEGIN

//类型 0：已绑定卡支付，1：输卡号支付 2：亲情圈支付 3：Apple 4:google 5:paypal
typedef NS_ENUM(NSInteger,BRPayWhere) {
    PAY_inCARD = 0,
    PAY_addCARD = 1,
    PAY_familyCircle = 2,
    PAY_inAPPLE = 3,
    PAY_inGoogle = 4,
    PAY_inPAYOAK = 5,
    PAY_inGRABPAY = 7,
};
// 流水类型：1-租借 3-会员 5-押金 7-报失,可用值:1,3,5,7
typedef NS_ENUM(NSInteger,BRPayType) {
//    PAY_TOPUP = 5,
    PAY_VIP = 3,
    PAY_RENT = 1,
//    PAY_TRANSFER = 1,
    PAY_LOST = 7,
    PAY_DEPOSIT = 5,
};

typedef enum {
    BRPAY_SUCC,
    BRPAY_FAILED,
} BRPAY_STAUS;

typedef void(^PayStatusBlock)(BOOL isSucc);

typedef void(^brApplePayStatusBlock)(BRPAY_STAUS status,BRPaymentModel *dto);

@interface BRPayManager : NSObject

+ (BRPayManager *)share;

@property (nonatomic,copy) NSString *payOrderNo;

@property (nonatomic,assign) BOOL paymentSuceeded;

@property (nonatomic,assign) BRPayWhere payWhere;

@property (nonatomic,assign) BRPayType payType;

@property (nonatomic,copy) PayStatusBlock paymentStatus;

@property (nonatomic,copy) PayStatusBlock fail;
//苹果预授权回调
@property (nonatomic,copy) brApplePayStatusBlock applePayBlock;
/// 预授权
@property (nonatomic,copy) BRStringBlock applePrePayBlock;
/// 请求后发生报错
@property (nonatomic,copy) BRStringBlock applePayReqBlock;

/// country:@"SG" currency:@"SGD" 支持的国家和货币
@property (nonatomic,copy) NSString *country;
@property (nonatomic,copy) NSString *currency;
/// 服务器返回支付秘钥，苹果支付使用，grab pay不需要赋值
@property (nonatomic,copy) NSString *clientSecret;
/// 支付成功后上报服务器的凭证
@property (nonatomic,copy) NSString *stripeId;

/// 苹果支付参数
@property (nonatomic,strong) NSDictionary *dic;
/// 是否支持 苹果支付 或者未添加卡
@property (nonatomic,assign) BOOL isSupportApplePay;

- (NSString *)br_getCardName:(STPCardFundingType)type;


/// 确认支付意图
- (void)pre_toConfirmStPay:(NSString *)clientSecret succ:(BRStringBlock)succ fail:(BRStringIntBlock)faile;

/// 主动取消授权 增加容错
- (void)pre_cancle;


/// 添卡Stripe校验 返回token 1
- (void)checkCard:(STPCardParams *)params isDefault:(BOOL)isDefault succ:(void(^)(BRAddCardModel * addModel))succ faile:(void(^)(void))fail;
/// 添加 2
- (void)addCard:(BRAddCardModel *)addModel succ:(void(^)(void))succ  faile:(void(^)(void))fail;

/// 获取支付方式列表
- (void)getPayList:(NSDictionary *)dic succ:(void (^)(NSDictionary * _Nonnull))succ faile:(void (^)(NSInteger))faile;


- (void)payment:(NSDictionary *)payDic from:(BRPayWhere)payWhere type:(BRPayType)payType;

/// 卡支付  PayPal
- (void)paymentCardWithParams:(NSDictionary *)params succ:(void(^)(NSDictionary *dic))succ  faile:(void(^)(NSInteger code, NSString * _Nonnull errMsg))fail;
/// 判断可否推押金
- (void)checkRefund:(void(^)(NSDictionary *dic))succ  faile:(void(^)(void))fail;
/// 押金 退款
- (void)refundDeposit:(void(^)(NSDictionary *dic))succ  faile:(void(^)(void))fail;
/// 金额计算
- (void)paymentAmount:(NSDictionary *)dic succ:(void (^)(NSDictionary * _Nonnull))succ faile:(void (^)(NSInteger))faile;

- (void)applePay:(NSDecimalNumber *)money;

/**
 遇到订单上报失败先缓存，方便在适当时机重新上报
 @param clientSecret clientSecret
 */
- (void)save:(NSString *)clientSecret;
/// 删除指定的缓存对象
/// @param clientSecret clientSecret 
- (void)remove:(NSString *)clientSecret;
/// 返回指定的对象，没有就返回 @{}
/// @param clientSecret clientSecret
- (NSDictionary *)getOrderDic:(NSString *)clientSecret;
/// 查询是否有未上报订单
- (BOOL)hasUnpayOreder;


#pragma mark - amount --
/// 默认货币符号
+ (NSString *)br_amount:(NSDecimalNumber *)amount;
/// 默认货币符号 2位小数
+ (NSString *)br_amountFloat:(CGFloat)amount;
+ (NSString *)br_amount:(NSDecimalNumber *)amount currency:(NSString *)currency;


@end

NS_ASSUME_NONNULL_END
